<template>
  <div class="logo-contaier">
    <div class="login">
      <div class="logo">
        <van-icon name="newspaper-o" class="news active" />
        <p>{{ i18n.$t('lookNews') }}</p>
      </div>
      <!-- <div class='logo-k'>
          <img src="@/assets/images/logo.gif" alt="">
        </div> -->
      <van-form @submit="onSubmit">
        <van-cell-group inset>
          <van-field
            v-model="username"
            name="用户名"
            label="用户名"
            placeholder="用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
          <van-field
            v-model="password"
            type="password"
            name="密码"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
        </van-cell-group>
        <p class='user-text'>
          <span @click='goToRegister'>注册</span>
        </p>
        <div style="margin: 16px">
          <van-button round block type="primary" native-type="submit">
            登录
          </van-button>
        </div>
      </van-form>
    </div>
    <!-- <MVerify /> -->
  </div>
</template>

<script lang="ts">
import { useI18n } from '@/i18nPlugin'
import { toRefs, defineComponent, reactive } from 'vue'
import { useRouter } from 'vue-router'

// import { MVerify } from '@/components'
//缓存
import { useStore } from 'vuex'
//接口
import { userLogin } from '@/config/api'

export default defineComponent({
  nem: 'Login',
  components: {
    // MVerify,
  },
  setup: () => {
    const i18n = useI18n()
    const router = useRouter()
    const store = useStore()
    const data = reactive({
      username: '',
      password: '',
      // logo_k:require('@/assets/images/logo.gif'),
    })
    let onSubmit = () => {
      console.log(data.username)
      console.log(data.password)
      let req = {
        userName:data.username,
        userPwd:data.password
      }
      userLogin(req).then((res:any) => {
        console.log(res)
        if(res.data.resCode === 1000) {
          (<any>window).utils.ui.Toast('登录成功！')
          let resData = {
            key:'userData',
            value:res.data.resData
          }
          store.commit('MUTATIONS_SET_STATE', resData)
          store.dispatch('ACTIONS_CHANGE_FOOTER_BAR',true)
          setTimeout(()=>{
            router.replace('/user')
          },1000)
        }
      })
    }
    const goToRegister = ()=> {
      router.replace('/UserRegister')
    }
    return { ...toRefs(data), i18n, onSubmit,goToRegister }
  },
})
</script>

<style scoped lang="scss">
.logo-contaier {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: $theme-bg;
  // background: url('./../../assets/images/login_bg.gif') no-repeat;
  background-size: 100% 100%;
}
.login {
  width: 100%;
  .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    .van-icon {
      font-size: 80px;
      color: $theme;
    }
    p {
      font-size: 40px;
      color: $theme !important;
      font-weight: bold;
    }
  }
  .van-form {
    width: 80%;
    margin: 0 auto;
    .van-button {
      background: $theme !important;
      border: 1px solid $theme !important;
      margin-top: 50px;
    }
  }
  .user-text {
    font-size: 12px;
    text-align: right;
    margin-top: 5px;
    display: inline-block;
    width: 90%;
    margin: 0 auto;
    color: #333;
    span {
      padding-bottom: 2px;
      border-bottom: 1px solid #333;
    }
  }
}
.logo-k {
  text-align: center;
}
:deep(.van-cell-group),
:deep(.van-field) {
  background: $theme-bg;
}
:deep(.van-field){
  border-bottom: 1px solid #ccc;
}
</style>
